#!/user/bin/env python
# -*- coding: utf-8 -*-
''' 
Author: Sjy
Description: 主程序配置信息管理模块 settings.py
'''

__all__= []

import os
import gui.components.util_file as UFile

global CONFIG_SYS_PATH  # 系统配置文件路径
CONFIG_SYS_PATH = "config/sys"

global CONFIG_USERS_PATH  # 用户配置文件路径
CONFIG_USERS_PATH = "config/users"
UFile.create_dir(CONFIG_SYS_PATH)   
UFile.create_dir(CONFIG_USERS_PATH)

global _CONFIG
_CONFIG = {}

def init():
    global _CONFIG
    _CONFIG = {}
    for root, dirs, files in os.walk(CONFIG_SYS_PATH):
        for file in files:
            fileExt = UFile.get_file_extesion(file)
            filename = UFile.get_file_name(file)
            if fileExt == ".json":
                try:
                    _CONFIG[filename] = UFile.open_json(os.path.join(root, file))
                except Exception as e:
                    print(e)

def get_data(name, defValue=None):
    try:
        return _CONFIG[name]
    except KeyError:
        return defValue
    

def get_index_data():
    return get_data("index")
def get_plugins_data():
    return get_data("plugins")
def get_docks_data():
    return get_data("docks")
